// 请求个人信息
// let avatar = document.querySelectorAll('.avatar');
// let description = document.querySelectorAll('.description');
// let phone = document.querySelectorAll('.phone');
// let userName = document.querySelectorAll('.userName');
userId = document.querySelectorAll(".content5-l1-col2-use > span").values;
let xhr = new XMLHttpRequest();
xhr.responseType = "json";
xhr.open(
    "GET",
    "https://mockapi.eolink.com/D2Hrx8Qe1911deea5ab4b01704bbfe0b97948d26eb2d31d/user/info"
);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
// 登录成功后get到token 用token请求全部的信息
xhr.setRequestHeader('token', '');
xhr.send();
xhr.onreadystatechange = function () {
    if (xhr.readyState === 4) {
        if (xhr.status >= 200 && xhr.status < 300) {
            // agreeP2.innerHTML = xhr.response.data.num;
            // console.log(xhr.response)
            if (xhr.response.username) {
                for (let i = 0; i < userName.length; i++) {
                    userName[i].innerText = xhr.response.username;
                }
            }
            if (xhr.response.id) {
                for (let i = 0; i < myId.length; i++) {
                    myId[i].innerText = xhr.response.id;
                }
            } else {
                for (let i = 0; i < myId.length; i++) {
                    myId[i].innerText = "设一个专属id吧~";
                }
            }
            // 不清楚头像照片要以哪种方式传输 就先按base64格式传输写着 已经先设置了一张实例头像
            if (xhr.response.avatar) {
                for (let i = 0; i < avatar.length; i++) {
                    avatar[i].setAttribute("src", xhr.response.avatar);
                    // avatar[i].setAttribute("src", "images/page5-peo.jpg");
                    console.log(avatar[i].src)
                }
            }
            if (xhr.response.description) {
                for (let i = 0; i < description.length; i++) {
                    description[i].innerText = xhr.response.description;
                }
            } else {
                for (let i = 0; i < description.length; i++) {
                    description[i].innerText = "能来一段freestyle的自述嘛";
                }
            }
            if (xhr.response.phone) {
                for (let i = 0; i < phone.length; i++) {
                    phone[i].innerText = xhr.response.phone;
                }
            } else {
                for (let i = 0; i < phone.length; i++) {
                    phone[i].innerText = "(your phone, 明白？)";
                }
            }
        }
    }
}